package com.hdoit.apollo.web.shop.apis;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hdoit.apollo.logical.shop.model.CustomerClassify;
import com.hdoit.apollo.logical.shop.service.ICustomerClassifyService;
import com.hdoit.apollo.logical.viewmodel.shop.CustomerClassifySearch;
import com.tennetcn.authority.component.webapi.BaseApi;
import com.tennetcn.authority.component.webapi.ResponseModel;
import com.tennetcn.authority.component.webapi.ResponseStatus;
import com.tennetcn.core.common.enums.pub.YesOrNoInteger;
import com.tennetcn.core.common.utils.DateUtils;
import com.tennetcn.data.enums.ModelStatus;


@Controller
@RequestMapping(value = "/api/v1/customer/",method = { RequestMethod.GET,RequestMethod.POST},produces = "application/json;charset=UTF-8")
@CrossOrigin(origins = "*", maxAge = 3600)
@Api(value="/api/v1/customer")
public class CustomerClassifyApi extends BaseApi{
	
	@Autowired
	private ICustomerClassifyService customerClassifyService;

	private final String saveCustomerClassifyApi="saveCustomerClassify";
	private final String getCustomerClassifyListApi="getCustomerClassifyList";
	
	
	 @RequestMapping(value = saveCustomerClassifyApi)
	    @ApiOperation(notes = saveCustomerClassifyApi, httpMethod = "POST", value = "保存客户信息")
	    public @ResponseBody String saveCustomerClassify(CustomerClassify customerClassify){
	    	CustomerClassify customerClassifyed = customerClassifyService.queryModel(customerClassify.getClassifyId());
	    	if(customerClassifyed==null){
	    		customerClassify.setCreateDate(DateUtils.getCurrent());
	    		customerClassify.setCreateUserId(getLoginId());
	    		customerClassify.setCreateUserName(getLoginName());
	    		customerClassify.setDeleteMark(YesOrNoInteger.no);
	    		customerClassify.setModelStatus(ModelStatus.add);
	    	}else{
	    		customerClassify.setModifyUserId(getLoginId());
	    		customerClassify.setModifyUserName(getLoginName());
	    		customerClassify.setModifyDate(DateUtils.getCurrent());
	    		customerClassify.setModelStatus(ModelStatus.update);
	    	}
	    	
	    	ResponseModel rm=new ResponseModel();
	    	if(!customerClassifyService.applyChange(customerClassify)){
	    		rm.setStatus(ResponseStatus.dataError);
	    	}
	    	return rm.toJson();
	    }

	    @RequestMapping(value = getCustomerClassifyListApi)
	    @ApiOperation(notes = getCustomerClassifyListApi, httpMethod = "GET", value = "获取客户分类列表")
	    public @ResponseBody String getCustomerClassifyList(CustomerClassifySearch search){
	    	List<CustomerClassify> customerClassifies = customerClassifyService.queryListMP(search,null);
	    	ResponseModel rm=new ResponseModel();
	    	rm.put("customerClassifies",customerClassifies);
	    	return rm.toJson();
	    }
}
